import os
from lockdoors import main
from lockdoors import sanitize
from lockdoors import shrts
import sys
from pathlib import Path
from datetime import datetime
from time import sleep
#VAR
yes = set(['yes', 'y', 'ye', 'Y'])
no = set(['no', 'n', 'nop', 'N'])
cwd = os.getcwd()
null = ""
###Cheatsheets
def expsh():
    shrts.clscprilo()
    print("\033[91mHere is the list of the files :\033[90m")
    print("\033[92m")
    os.system("     find " + shrts.getinstalldir() + "/EXPLOITATION/CHEATSHEETS/ -type f")
    print("\033[90m")
    shrts.okex()
##TOOLS
def Findsploit():
    Findsploit.title = "Findsploit : Find exploits in local and online databases instantly"
    tool_dir = "/EXPLOITATION/Tools/Findsploit"
    if os.path.exists('/usr/local/bin/Findsploit'):
        shrts.prilogspc()
        os.system("git clone  https://github.com/1N3/Findsploit.git " + shrts.getinstalldir() + tool_dir + null)
        shrts.prilogspc()
        print("\033[92m           " + Findsploit.title + "\033[90m")
        shrts.spc()
        ans = sanitize.bash_escape_restrictor(input("\033[92mWhat exploits are you looking  ? : \033[90m"))
        os.system("Findsploit " + ans)
        shrts.okex()
    else:
        shrts.prilogspc()
        print("\033[92m           " + Findsploit.title + "\033[90m")
        shrts.spc()
        print("\033[91mDownloading ...\033[0m")
        shrts.spc()
        os.system("git clone https://github.com/1N3/Findsploit.git " + shrts.getinstalldir() + tool_dir + null)
        shrts.prilogspc()
        print("\033[92m           " + Findsploit.title + "\033[90m")
        shrts.spc()
        shrts.prilogspc()
        print("\033[91mInstalling ...\033[0m.")
        os.system("cd " + shrts.getinstalldir() + tool_dir + " && pip3 install -r " + shrts.getinstalldir() + tool_dir + "/requirements.txt" + null)
        os.system("sh " + shrts.getinstalldir() + tool_dir + "/install.sh")
        os.system("ln -s /usr/bin/findsploit /usr/local/bin/Findsploit")
        shrts.spc()
        print("You can now use " + "\033[91m" + Findsploit.title + "\033[90m" + " from Lockdoor [\033[92m Lockdoor \033[90m ]" )
        shrts.okex()
def Pompem():
    Pompem.title = "Pompem : an Exploit and Vulnerability Finder"
    tool_dir = "/EXPLOITATION/Tools/Pompem"
    if os.path.exists('/usr/local/bin/Pompem'):
        shrts.prilogspc()
        os.system("git clone https://github.com/rfunix/Pompem.git " + shrts.getinstalldir() + tool_dir + null)
        shrts.prilogspc()
        print("\033[92m           " + Pompem.title + "\033[90m")
        shrts.spc()
        ans = sanitize.bash_escape_restrictor(input("\033[92mWhat exploits are you looking  ? : \033[90m"))
        os.system("python3 " + shrts.getinstalldir() + tool_dir + "/pompem.py -s " + ans)
        shrts.spc()
        shrts.okex()
    else:
        shrts.prilogspc()
        print("\033[92m           " + Pompem.title + "\033[90m")
        shrts.spc()
        print("\033[91mDownloading ...\033[0m")
        shrts.spc()
        os.system("git clone https://github.com/rfunix/Pompem.git " + shrts.getinstalldir() + tool_dir + null)
        shrts.prilogspc()
        print("\033[92m           " + Pompem.title + "\033[90m")
        shrts.spc()
        shrts.prilogspc()
        print("\033[91mInstalling ...\033[0m.")
        shrts.spc()
        os.system("cd " + shrts.getinstalldir() + tool_dir + " && pip3 install -r " + shrts.getinstalldir() + tool_dir + "/requirements.txt" + null)
        os.system("""echo "#!/bin/bash" > /usr/local/bin/Pompem""")
        os.system("""echo "#Dev : Sofiane Hamlaoui" >> /usr/local/bin/Pompem""")
        os.system("echo python3 " + shrts.getinstalldir() + tool_dir + "/pompem.py >> /usr/local/bin/Pompem")
        os.system("chmod +x /usr/local/bin/Pompem")
        print(("You can now use " + "\033[91m" + Pompem.title + "\033[90m" + " from Lockdoor [\033[92m Lockdoor \033[90m ]" ))
        shrts.spc()
        shrts.okex()
def rfix():
    rfix.title = "Rfix : Python tool that helps RFI exploitation."
    tool_dir = "/EXPLOITATION/Tools//rfix"
    if os.path.exists('/usr/local/bin/rfix'):
        shrts.prilogspc()
        os.system("git clone https://github.com/joaogmauricio/rfix.git " + shrts.getinstalldir() + tool_dir + null)
        shrts.prilogspc()
        print("\033[92m           " + rfix.title + "\033[90m")
        shrts.spc()
        print("\033[92m Usage: rfix target_url payload_path. \033[90m")
        shrts.spc()
        print("Example: rfix http://target_host/index.php?flawed_param= php.txt ")
        shrts.spc()
        target = sanitize.bash_escape_restrictor(input("\033[92m Choose a Target : \033[90m"))
        payload = sanitize.bash_escape_restrictor(input("\033[92m Choose the payload path : \033[90m"))
        os.system("python2 " + shrts.getinstalldir() + tool_dir + "/rfix.py " + target + " " + payload)
        shrts.spc()
        shrts.okex()
    else:
        shrts.prilogspc()
        print("\033[92m           " + rfix.title + "\033[90m")
        shrts.spc()
        print("\033[91mDownloading ...\033[0m")
        shrts.spc()
        os.system("git clone https://github.com/joaogmauricio/rfix.git " + shrts.getinstalldir() + tool_dir + null)
        shrts.prilogspc()
        print("\033[92m           " + rfix.title + "\033[90m")
        shrts.spc()
        shrts.prilogspc()
        print("\033[91mInstalling ...\033[0m.")
        shrts.spc()
        os.system("""echo "#!/bin/bash" > /usr/local/bin/rfix""")
        os.system("""echo "#Dev : Sofiane Hamlaoui" >> /usr/local/bin/rfix""")
        os.system("echo python3 " + shrts.getinstalldir() + tool_dir + "/rfix.py >> /usr/local/bin/rfix")
        os.system("chmod +x /usr/local/bin/rfix")
        print(("You can now use " + "\033[91m" + rfix.title + "\033[90m" + " from Lockdoor [\033[92m Lockdoor \033[90m ]" ))
        shrts.spc()
        shrts.okex()
def inurlbr():
    inurlbr.title = "inurlbr : Python tool that helps RFI exploitation."
    tool_dir = "/EXPLOITATION/Tools/inurlbr"
    if os.path.exists('/usr/local/bin/inurlbr'):
        shrts.prilogspc()
        os.system("git clone https://github.com/googleinurl/SCANNER-INURLBR.git " + shrts.getinstalldir() + tool_dir + null)
        shrts.prilogspc()
        print("\033[92m           " + inurlbr.title + "\033[90m")
        shrts.spc()
        print("type : inurlbr --help for more options ")
        shrts.spc()
        print("Cheatsheets that can help you with this :")
        shrts.spc()
        print("\033[92m" + shrts.getinstalldir() + '/Google FU.pdf \033[92m')
        print("\033[92m" + shrts.getinstalldir() + '/GHDB.pdf \033[92m')
        shrts.spc()
        dork = sanitize.bash_escape_restrictor(input("\033[92m Choose a Dork : \033[90m"))
        savefile = sanitize.bash_escape_restrictor(input("\033[92m output file ? (Ex : results.txt) : \033[90m"))
        os.system("php " + shrts.getinstalldir() + tool_dir + "/inurlbr.php --dork " + dork + " -s " + savefile)
        shrts.okex()
    else:
        shrts.prilogspc()
        print("\033[92m           " + inurlbr.title + "\033[90m")
        shrts.spc()
        print("\033[91mDownloading ...\033[0m")
        shrts.spc()
        os.system("git clone https://github.com/googleinurl/SCANNER-INURLBR.git " + shrts.getinstalldir() + tool_dir + null)
        shrts.prilogspc()
        print("\033[92m           " + inurlbr.title + "\033[90m")
        shrts.spc()
        shrts.prilogspc()
        print("\033[91mInstalling ...\033[0m.")
        shrts.spc()
        os.system("""echo "#!/bin/bash" > /usr/local/bin/inurlbr""")
        os.system("""echo "#Dev : Sofiane Hamlaoui" >> /usr/local/bin/inurlbr""")
        os.system("echo php " + shrts.getinstalldir() + tool_dir + "/inurlbr.php >> /usr/local/bin/inurlbr")
        os.system("chmod +x /usr/local/bin/inurlbr")
        print(("You can now use " + "\033[91m" + inurlbr.title + "\033[90m" + " from Lockdoor [\033[92m Lockdoor \033[90m ]" ))
        shrts.okex()
def burp():
    burp.title = "BurpSuite : Web vulnerability scanner."
    tool_dir = "/EXPLOITATION/Tools/burp"
    if os.path.exists('/usr/local/bin/burp'):
        shrts.prilogspc()
        shrts.prilogspc()
        print("\033[92m           " + burp.title + "\033[90m")
        shrts.spc()
        os.system("burpsuite")
        shrts.okex()
    else:
        shrts.prilogspc()
        print("\033[92m           " + burp.title + "\033[90m")
        shrts.spc()
        print("\033[91mDownloading ...\033[0m")
        shrts.spc()
        os.system("mkdir " + shrts.getinstalldir() + tool_dir)
        os.system("wget -O " + shrts.getinstalldir() + tool_dir + "/burp.jar https://portswigger.net/DownloadUpdate.ashx\?Product\=Free")
        shrts.prilogspc()
        print("\033[92m           " + burp.title + "\033[90m")
        shrts.spc()
        shrts.prilogspc()
        print("\033[91mInstalling ...\033[0m.")
        shrts.spc()
        os.system("""echo "#!/bin/bash" > /usr/local/bin/burp""")
        os.system("""echo "#Dev : Sofiane Hamlaoui" >> /usr/local/bin/burp""")
        os.system("echo java -jar " + shrts.getinstalldir() + tool_dir + "/burp.jar >> /usr/local/bin/burp")
        os.system("chmod +x /usr/local/bin/burp")
        print(("You can now use " + "\033[91m" + burp.title + "\033[90m" + " from Lockdoor [\033[92m Lockdoor \033[90m ]" ))
        shrts.okex()
# More :
def linexpsug():
    linexpsug.title = "linux-exploit-suggester2 : A perl Linux exploit suggester script"
    tool_dir = "/EXPLOITATION/linux-exploit-suggester"
    shrts.prilogspc()
    os.system("git clone https://github.com/jondonas/linux-exploit-suggester-2.git " + shrts.getinstalldir() + tool_dir + null)
    shrts.clscprilo()
    print("\033[92m           linux-exploit-suggester2 Downlaoded successfully \033[90m")
    shrts.spc()
    print("\033[92m           Check " + shrts.getinstalldir() + tool_dir +" Folder\033[90m")
    shrts.okex()
###Menu
def menu():
    shrts.clscprilo()
    print("""\033[94m
        [ EXPLOITATION ]

        Make A Choice :\033[90m
        \033[91m -[!]----- Tools ------[!]-\033[90m
            \033[93m1)  Findsploit
            2)  Pompem
            3)  rFix
            4)  Inurlbr
            5)  BurpSuite
            6)  Linux exploit suggester2\033[90m

        \033[91m -[!]----- Cheatsheets ------[!]-\033[90m
            \033[93m7) Exploitation Cheatsheets\033[90m
    ------------------------
    \033[94mb)    Back to ROOT MENU
    q)    Leave  Lockdoor\033[90m
       """)
    choice = input("\033[92mLockdoor@Exploitation~# \033[0m")
    os.system('clear')
    if choice == "1":
      Findsploit()
    elif choice == "2":
      Pompem()
    elif choice == "3":
      rfix()
    elif choice == "4":
      inurlbr()
    elif choice == "5":
      burp()
    elif choice == "6":
      linexpsug()
    elif choice =="7":
        expsh()
    elif choice == "b":
      main.menu()
    elif choice == "q":
        shrts.prilogspc()
        now = datetime.now()
        dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
        print("                 \033[91m-[!]- LOCKDOOR IS EXITING -[!]-\033[0m")
        shrts.spc()
        print("                 \033[91m-[!]- EXITING AT " + dt_string + " -[!]-\033[0m")
        sys.exit()
    elif choice == "":
      menu()
    else:
      menu()
